package com.xxx.config;

import com.xxx.handler.TimeCostAspect;
import com.xxx.property.XDemoProperties;
import com.xxx.service.XDemoService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * the class of advance
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2024-06-14
 */
@Configuration
@EnableConfigurationProperties({
        XDemoProperties.class,
})
public class XDemoAutoConfiguration {

    private final XDemoProperties xDemoProperties;

    public XDemoAutoConfiguration(XDemoProperties xDemoProperties) {
        this.xDemoProperties = xDemoProperties;
    }

    /**
     * timecsot 统计方法耗时 自动装配
     * @return
     */
    @ConditionalOnProperty(prefix = "x.starter.demo", name = "enable", havingValue = "true", matchIfMissing = true)
    @Bean
    public TimeCostAspect timeCostAspect() {
        return new TimeCostAspect();
    }


    /**
     * logger sayhello 自动装配
     * @return
     */
    @Bean
    public XDemoService xDemoService() {
        return new XDemoService(xDemoProperties);
    }
}
